const TOKEN_KEY = 'token'

function getCookie(key: string) {
  const cookie = document.cookie
  if (cookie) {
    const arr = cookie.split('; ')
    for (const item of arr) {
      const i = item.split('=')
      if (i[0] === key) {
        return i[1]
      }
    }
  }
  return ''
}

function getToken() {
  // return getCookie(TOKEN_KEY)
  return uni.getStorageSync(TOKEN_KEY)
}
function setToken(token: string) {
  uni.setStorageSync(TOKEN_KEY, token)
}
function clearToken() {
  uni.removeStorageSync(TOKEN_KEY)
}
/** 登出（清token） */
function logout() {
  clearToken()
}
function jumpToLogin() {
  if (uni.getStorageSync('isNoLogin')) {
    uni.navigateTo({
      url: '/pages/login/index'
    })
    return
  }
}
export { getToken, setToken, clearToken, logout }
